<?php
class Admin_Login_Action extends NICED_Action 
{       
	public function execute() 
	{
		$controller = $this->getController();
		$request    = $controller->getRequest();			
        $act        = $request->loadParam("act");
        $password   = $request->loadParam("password");
        $session_id = $request->loadParam("session_id");

		try
		{
            //if login frontend
		    $model      = $controller->getModel('Login.Index');
            $bool       = $model->isLogin($session_id);

            if (!$bool)
            {
                //NICED_Application::forward("Login.Index");
                header("Location: /login");
            }

            //if not login frontend,do login
            if (!$act)
            {
                return self::SUCCESS;
            }

            $user_id    = Session::getUserId();

            //check is login admin
		    $model      = $controller->getModel('Admin.Index');

            $bool = $model->isLogin($session_id);

            //if not login admin, do login
            if (!$bool)
            {
                $model->login($user_id, $password);
            }

            //login success, to admin page
            header("Location: /admin/index");
            //to home page or referer page
		}
		catch (Exception $e)
		{
			$controller->handleException(new NICED_Exception($e->getMessage()));

			return self::SUCCESS;
		}

		return self::SUCCESS;
	}

}//end class
